<?php
namespace common\components;
use yii\helpers\Html;
use yii\helpers\ArrayHelper;
class CreateExhibitionDropList
{
    /**
     * @name 创建展会下来列表
     * @param array $exhibitionData   展会数据
     * @param object $model 数据模型
     * @param string $locateUrl 跳转数据
     */
    public static function createDropList($exhibitionData,$model,$locateUrl,$prompt = '展会切换',$style = false, $class = false, $setSeletDiv = false,$item = 'id')
    {
        //print_r($model->$item);
        //exit();
        if (empty($exhibitionData)) {
        	return [];
        } else {
            $str = '';
            $config['onchange'] = 'window.location.href = "' . $locateUrl . '&exhibitionId=' . '"+$(this).val();';
            if ($prompt) {
            	$config['prompt'] = $prompt;            	
   
            }   
            $title = '';
            if ($setSeletDiv === true) {
            	if (empty($model->$item)) {
            	    $title = $prompt;
            	} else {
            	    foreach ($exhibitionData as $value) {
            	        if ($model->$item == $value['id']) {
            	            $title = $value['title'];
            	            break;
            	        }
            	    }
            	}
            	$str = '<div class="selectDiv">'.$title.'</div>';
            }
            
            if ($style) {
                $config['style'] = $style;
            }
            if ($class) {
            	$config['class'] = $class;
            }
            return $str.Html::activeDropDownList($model, $item,
                ArrayHelper::map($exhibitionData, 'id', 'title'),$config                
            );
        }     
    }
}